import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/antd_icons.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 打印机详情
///
class PrinterInfo extends StatefulWidget {
  const PrinterInfo({Key? key}) : super(key: key);

  @override
  State<PrinterInfo> createState() => _PrinterInfoState();
}

class _PrinterInfoState extends State<PrinterInfo> {
  Widget get actions {
    return BrnIconAction(
      iconPressed: showSingleButtonDialog,
      child: const Icon(AntdIcons.questionCircleFill, color: Colors.white, size: Sizes.default20),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.getDefaultBrnAppBar('云打印机', actions: actions),
      body: SingleChildScrollView(
        padding: const EdgeInsets.only(
            left: Sizes.default15, right: Sizes.default15, top: Sizes.default10),
        child: Column(
          children: [
            Container(
              margin: const EdgeInsets.only(bottom: Sizes.default15),
              padding: const EdgeInsets.only(
                  left: Sizes.default15, top: Sizes.default10, bottom: Sizes.default10),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default8)),
              child: Column(
                children: [
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Text('店铺名称：默林如斯的肠粉早餐店(凤凰广场店)',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color363)),
                  ),
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Text('设备商：动力云',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color363)),
                  ),
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Text('终端号：A405979708',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color363)),
                  ),
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Text('秘钥：A8791D3042jre56',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color363)),
                  ),
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Text('连接状态：正常',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color363)),
                  ),
                ],
              ),
            ),
            Container(
              margin: const EdgeInsets.only(bottom: Sizes.default15),
              padding: const EdgeInsets.only(
                  left: Sizes.default15, top: Sizes.default10, bottom: Sizes.default10),
              decoration: BoxDecoration(
                  color: Colors.white, borderRadius: BorderRadius.circular(Sizes.default8)),
              child: Column(
                children: [
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Text('店铺名称：默林如斯的肠粉早餐店(北部湾店)',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color363)),
                  ),
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Text('设备商：动力云',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color363)),
                  ),
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Text('终端号：A405979707',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color363)),
                  ),
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Text('秘钥：A8791D3042jre56',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color363)),
                  ),
                  Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    child: Text('连接状态：异常',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color363)),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  void showSingleButtonDialog() {
    showDialog<void>(
        context: context,
        builder: (BuildContext context) {
          return BrnDialog(
            themeData: BrnDialogConfig(
              dialogWidth: 300,
              radius: Sizes.default10,
              backgroundColor: Colors.white,
              titlePaddingLg: EdgeInsets.zero,
              titlePaddingSm: EdgeInsets.zero,
              titleTextAlign: TextAlign.center,
              contentPaddingLg: EdgeInsets.zero,
              contentPaddingSm: EdgeInsets.zero,
              contentTextAlign: TextAlign.left,
            ),
            titleWidget: Container(
              height: Sizes.default50,
              alignment: Alignment.center,
              child: Text('如何添加打印机？',
                  style: StylesUtils.customTextStyle(
                      fontSize: Sizes.default18, color: ColorsUtils.color000)),
            ),
            contentWidget: Container(
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default10),
              child: Column(
                children: [
                  Container(
                    alignment: Alignment.centerLeft,
                    child: Text('添加第三方云打印机设置的步骤如下：',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default15, color: ColorsUtils.color333)),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: const EdgeInsets.only(top: Sizes.default8),
                    child: Text('1.登录第三方打印机后台；',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default15, color: ColorsUtils.color333)),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: const EdgeInsets.only(top: Sizes.default8),
                    child: Text('2.添加终端 (即打印机)；',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default15, color: ColorsUtils.color333)),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: const EdgeInsets.only(top: Sizes.default8),
                    child: Text('3.在应用中心中找到并打开小默外卖；',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default15, color: ColorsUtils.color333)),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: const EdgeInsets.only(top: Sizes.default8),
                    child: Text('5.选择对应的店铺再点击完成，然后点击确定完成授权；',
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default15, color: ColorsUtils.color333)),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: const EdgeInsets.only(top: Sizes.default8),
                    child: Text.rich(TextSpan(
                        style: StylesUtils.customTextStyle(
                            fontSize: Sizes.default15, color: ColorsUtils.color333),
                        children: [
                          const TextSpan(text: '6.点击 '),
                          WidgetSpan(
                            child: ToolsUtils.getUrlSvg(
                                'https://cdn7.axureshop.com/demo/1525603/images/余额转账/u2052.svg',
                                width: Sizes.default13,
                                height: Sizes.default13),
                            alignment: PlaceholderAlignment.middle,
                          ),
                          const TextSpan(text: ' 进行打印机绑定，选择已添加的打印机并保存，即可完成绑定。')
                        ])),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    margin: const EdgeInsets.only(top: Sizes.default8),
                    child: Text('(注：目前仅支持易联云云打印机，后续将开放更多设备商。)',
                        style: StylesUtils.customTextStyle(color: ColorsUtils.color999)),
                  ),
                  Container(
                    alignment: Alignment.center,
                    padding: const EdgeInsets.only(top: Sizes.default15),
                    child: SizedBox(
                      width: 205,
                      height: Sizes.default40,
                      child: GFButton(
                          focusColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6),
                          onPressed: () {
                            Navigator.of(context).pop();
                          },
                          text: '我知道了',
                          textStyle: StylesUtils.customTextStyle(
                              fontSize: Sizes.default16, color: ColorsUtils.colorFf6),
                          shape: GFButtonShape.pills,
                          type: GFButtonType.outline,
                          size: GFSize.LARGE,
                          color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6)),
                    ),
                  )
                ],
              ),
            ),
          );
        });
  }
}
